import request from '@/utils/request'
import type { SPUResponseData } from './type'

enum API {
  UPDATE_SPU_SALE_ATTR_URL = '/admin/product/updateSpuSaleAttr',
  ADD_SPU_SALE_ATTR_URL = '/admin/product/saveSpuSaleAttr',
  UPDATE_SPU_SALE_ATTR_VALUE_URL = '/admin/product/updateSpuSaleAttrValue',
  ADD_SPU_SALE_ATTR_VALUE_URL = '/admin/product/saveSpuSaleAttrValue',
  UPDATE_SPU_IMAGE_URL = '/admin/product/updateSpuImage',
  ADD_SPU_IMAGE_URL = '/admin/product/saveSpuImage',
  DELETE_SPU_SALE_ATTR_URL = '/admin/product/deleteSpuSaleAttr',
  DELETE_SPU_SALE_ATTR_VALUE_URL = '/admin/product/deleteSpuSaleAttrValue',
  GET_SKU_INFO = '/admin/product/findBySpuId',

  // 获取已有spu
  GET_PRODUCTLIST_URL = '/admin/product',
  // 获取全部品牌
  GET_TRADE_MARK_URL = '/admin/product/baseTrademark/getTrademarkList',
  // 获取spu的全部照片
  GET_SPU_IMAGE_URL = '/admin/product/spuImageList',
  // 获取spu的销售属性
  GET_SPU_SALE_ATTR_URL = '/admin/product/spuSaleAttrList',
  // 获取全部销售属性
  GET_BASE_SALE_ATTR_URL = '/admin/product/baseSaleAttrList',
  // 获取spu详情信息
  GET_SPU_INFO_URL = '/admin/product/getSpuById',
  // 更新spu
  UPDATE_SPU_URL = '/admin/product/updateSpuInfo',
  // 新增spu
  ADD_SPU_URL = '/admin/product/saveSpuInfo',
  // 删除spu
  DELETE_SPU_URL = '/admin/product/deleteSpu',
  GET_ATTR_INFO_LIST_URL = '/admin/product/attrInfoList',
  ADD_SKU_URL = '/admin/product/saveSkuInfo',
}

export const getProductList = (
  page: number,
  limit: number,
  category3Id: number | string
) =>
  request.get<any, SPUResponseData>(
    `${API.GET_PRODUCTLIST_URL}/${page}/${limit}?category3Id=${category3Id}`
  )
export const getTradeMarkList = () =>
  request.get<any, any>(API.GET_TRADE_MARK_URL)
export const getBaseSaleAttrList = () =>
  request.get<any, any>(API.GET_BASE_SALE_ATTR_URL)
export const getSpuImageList = (spuId: number | string) =>
  request.get<any, any>(`${API.GET_SPU_IMAGE_URL}/${spuId}`)
export const getSpuSaleAttrList = (spuId: number | string) =>
  request.get<any, any>(`${API.GET_SPU_SALE_ATTR_URL}/${spuId}`)
export const addOrUpdateSpu = (data: any) =>
  request.post<any, any>(data.id ? API.UPDATE_SPU_URL : API.ADD_SPU_URL, data)

export const deleteSpu = (spuId: number | string) =>
  request.delete<any, any>(`${API.DELETE_SPU_URL}/${spuId}`)
export const getSpuInfo = (spuId: number | string) =>
  request.get<any, any>(`${API.GET_SPU_INFO_URL}/${spuId}`)
export const getAttrInfoList = (
  category1Id: number | string,
  category2Id: number | string,
  category3Id: number | string
) =>
  request.get<any, any>(
    `${API.GET_ATTR_INFO_LIST_URL}/${category1Id}/${category2Id}/${category3Id}`
  )

  export const addSku = (data: any) =>
  request.post<any, any>(API.ADD_SKU_URL, data)

/*******************/

export const updateSpuSaleAttr = (data: any) =>
  request.post<any, any>(API.UPDATE_SPU_SALE_ATTR_URL, data)
export const addSpuSaleAttr = (data: any) =>
  request.post<any, any>(API.ADD_SPU_SALE_ATTR_URL, data)
export const updateSpuSaleAttrValue = (data: any) =>
  request.post<any, any>(API.UPDATE_SPU_SALE_ATTR_VALUE_URL, data)
export const addSpuSaleAttrValue = (data: any) =>
  request.post<any, any>(API.ADD_SPU_SALE_ATTR_VALUE_URL, data)
export const updateSpuImage = (data: any) =>
  request.post<any, any>(API.UPDATE_SPU_IMAGE_URL, data)
export const addSpuImage = (data: any) =>
  request.post<any, any>(API.ADD_SPU_IMAGE_URL, data)
export const deleteSpuSaleAttr = (
  spuId: number | string,
  saleAttrId: number | string
) =>
  request.delete<any, any>(
    `${API.DELETE_SPU_SALE_ATTR_URL}/${spuId}/${saleAttrId}`
  )
export const deleteSpuSaleAttrValue = (
  spuId: number | string,
  saleAttrId: number | string,
  saleAttrValueId: number | string
) =>
  request.delete<any, any>(
    `${API.DELETE_SPU_SALE_ATTR_VALUE_URL}/${spuId}/${saleAttrId}/${saleAttrValueId}`
  )

export const getSkuInfo = (spuId: number | string) =>
  request.get<any, any>(`${API.GET_SKU_INFO}/${spuId}`)
